<template>
  <SuperTable ref="superTableRef" search pager border align="center" :columns="columns" :data-request="fetchData" :export-config="{}" header-title="智能提醒" />
  <HandleModal v-model:show-modal="showModal" :data="table.currentData" @modal-ok="refreshTableFn" />
</template>

<script setup lang="ts">
import SuperTable from '@/framework/components/core/super-table/super-table.vue';
import HandleModal from '@/modules/smart-reminders/pages/smart-reminders/components/handle-modal/handle-modal.vue';
import { VxeGridPropTypes } from 'vxe-table';
import type { TableColumnItem } from './columns';
import { baseColumns } from './columns';
import { reactive, ref } from 'vue';
import { warnSearch } from '@/modules/smart-reminders/api';

/**
 * modal
 */
const showModal = ref(false);
/**
 * table
 */
const table = reactive({
  currentData: {},
});
const superTableRef = ref<InstanceType<typeof SuperTable>>();
const columns: TableColumnItem[] = [
  ...baseColumns,
  {
    title: '操作',
    field: '$action',
    hideInSearch: true,
    align: 'center',
    fixed: 'right',
    width: 100,
    actions: ({ row }) => [
      {
        label: '查看',
        onClick: () => {
          table.currentData = row;
          showModal.value = true;
        },
      },
    ],
  },
];
const fetchData = async (ori: VxeGridPropTypes.ProxyAjaxQueryParams) => {
  let data = superTableRef.value?.getFormModel();
  let params = {
    pageSize: ori.page.pageSize,
    pageNum: ori.page.currentPage,
    orderBy: [
      {
        field: 'cautionTime',
        order: 'desc',
      },
    ],
    ...data,
  };
  data.cautionTimeBtw ? (params.cautionTimeBtw = data.cautionTimeBtw.join()) : delete params.cautionTimeBtw;
  let res = await warnSearch(params);
  return res.result;
  // return {
  //   data: [{}, {}, {}],
  //   pageIndex: 1,
  //   pageSize: 10,
  //   total: 100,
  // };
};
const refreshTableFn = () => {
  superTableRef.value?.refreshTable();
};
</script>

<style scoped lang="less"></style>
